package com.tyc.framework;

import java.util.HashMap;
import java.util.UUID;

/**
 * hashmap不安全原因
 * 1.7 头插法扩容引起环状
 * 1.8 会出现数据覆盖
 *https://baijiahao.baidu.com/s?id=1675991555833901875&wfr=spider&for=pc
 * hashtable效率低
 *
 * concurrenthashmap
 *
 */
public class HashMapTest {
    public static void main(String[] args) throws InterruptedException {
        // JDK 7可能会引起put时死循环
        final HashMap<String,String> map = new HashMap<>(2);
        Thread thread = new Thread(() -> {
            for (int i = 0; i < 1000; i++) {
                new Thread(() -> {
                    map.put(UUID.randomUUID().toString(), "");
                }).start();
            }
        });
        thread.start();
        thread.join();
    }
}
